package com.cvr.project.viewmodel;

import android.annotation.SuppressLint;

import com.cvr.project.entity.IDCardEntity;
import com.cvr.project.entity.ORCEntity;
import com.cvr.project.repertory.BaseResponse;
import com.cvr.project.repertory.BaseViewModel;
import com.cvr.project.repertory.DataRepository;
import com.cvr.project.repertory.SingleLiveEvent;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

import okhttp3.MultipartBody;

/**
 * _ooOoo_
 * o8888888o
 * 88" . "88
 * (| -_- |)
 * O\ = /O
 * ____/`---'\____
 * .   ' \\| |// `.
 * / \\||| : |||// \
 * / _||||| -:- |||||- \
 * | | \\\ - /// | |
 * | \_| ''\---/'' | |
 * \ .-\__ `-` ___/-. /
 * ___`. .' /--.--\ `. . __
 * ."" '< `.___\_<|>_/___.' >'"".
 * | | : `- \`.;`\ _ /`;.`/ - ` : | |
 * \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 * `=---='
 * .............................................
 * 佛祖保佑             永无BUG
 *
 * @author :created by master
 * time :2021年7月7日15:07:28
 * 描述：mainactivity
 */
public class MainViewModel extends BaseViewModel {
    public SingleLiveEvent<IDCardEntity> icCardLoginLiveData;
    public SingleLiveEvent<ORCEntity> icOrcLoginLiveData;
    public SingleLiveEvent<String> errorTipLiveData;

    public MainViewModel() {
        super();
        icCardLoginLiveData = new SingleLiveEvent<>();
        icOrcLoginLiveData = new SingleLiveEvent<>();
        errorTipLiveData = new SingleLiveEvent<>();
    }

    /**
     * 身份证登录
     */
    public void icCardLogin(String families_id, String phone) {
        DataRepository.getInstance().icCardLogin(families_id, phone).observe(mLifecycleOwner, response -> {
            if (response.getStatus().equals(BaseResponse.CODE_SUCCESS)) {
                icCardLoginLiveData.postValue(response.getData());
            } else {
                errorTipLiveData.postValue(response.getMsg());
            }
        });
    }

    /**
     * 人脸登录，截取摄像头人脸图片
     */
    public void icOrcLogin(List<MultipartBody.Part> file) {
        DataRepository.getInstance().icOrcLogin(file).observe(mLifecycleOwner, response -> {
            if (response.getStatus().equals(BaseResponse.CODE_SUCCESS)) {
                icOrcLoginLiveData.postValue(response.getData());
            } else {
                errorTipLiveData.postValue(response.getMsg());
            }
        });
    }
}
